package linwen.wang.redis.jedis;

import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName JedisSortSet
 * @Description
 * @Author lin
 * @Date 2022/3/2 下午9:40
 * @Version V1.0
 */
public class JedisSortSet {


    // sortedset
    @Test
    public void test() {
        Jedis jedis = new Jedis();
        jedis.flushAll();
        //向有序集合中添加多个成员
        Map<Double,String> map = new HashMap<>();
        map.put(60.0, "Alan");
        map.put(70.0, "Jack");
        map.put(75.0, "Tom");

        jedis.zadd("rank", 60.0,"Alan");
        jedis.zadd("rank", 70.0,"Jack");
        jedis.zadd("rank", 75.0,"Tom");

        //返回所有成员
        System.out.println(jedis.zrange("rank", 0, -1));

        //带有分数地返回所有成员,字符串由ASCII码表示
        System.out.println(jedis.zrangeWithScores("rank", 0, -1));

        //增加成员分数
        jedis.zincrby("rank", 0.5, "Alan");
        System.out.println(jedis.zscore("rank", "Alan"));

        //返回分数在60到70之间的成员
        System.out.println(jedis.zrangeByScore("rank", 60, 70));
        jedis.close();
    }
}

